home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 4 code / Poly. in Code Resources / Virtual WDEF / WindowDef_main.cp < prev    next >
Encoding:
Text File  |  1991-01-10  |  3.5 KB  |  139 lines  |  [TEXT/MPS ]

  1. /*
  2.     WindowDef_main.cp
  3.     
  4.     Main function for all WindowDef's.
  5.     
  6.     C++ Implementation by Patrick Beard.
  7.     
  8.     ©1990 by Patrick C. Beard.  All rights reserved.
  9.  */
  10.  
  11. #include <StdDef.h>
  12. #include <Memory.h>
  13. #include <Events.h>
  14.  
  15. #include "VirtualWorld.h"
  16.  
  17. // The next two lines will change depending on the WDEF being built
  18.  
  19. #include "IconWDEF.h"
  20. #define WINDOWCLASS IconWindowDef
  21.  
  22. // structure to maintain our storage.
  23.  
  24. struct WindowDefinitionData {
  25.     WStateData        states;
  26.     VirtualWorld    *world;
  27. };
  28.  
  29. typedef WindowDefinitionData *WindowDefinitionDataPtr, **WindowDefinitionDataHandle;
  30.  
  31. static WindowDefinition* theWindowDef;    // global to maintain our window def object.
  32.  
  33. pascal long main(short varCode, WindowPeek theWindow, short message, long param)
  34. {
  35.     long result = 0;
  36.     
  37.     // see if the command key is down for debugging purposes.
  38.     KeyMap theKeys;
  39.     GetKeys(theKeys);
  40.     Boolean commandKeyDown = (theKeys[1] & (1L<<15)) != 0;
  41.     
  42.     if(commandKeyDown)
  43.         DebugStr("\pChecking theWorld.");
  44.     
  45.     // retrieve our global context from the window record.
  46.     VirtualWorld* theWorld;
  47.     WindowDefinitionDataHandle theData = (WindowDefinitionDataHandle)theWindow->dataHandle;
  48.     if(theData) {
  49.          theWorld = (**theData).world;
  50.         theWorld->Enter();
  51.     }
  52.  
  53.     switch(message) {
  54.     case wNew:
  55.         // create a world to support virtual functions.
  56.         if(commandKeyDown)
  57.             DebugStr("\pCreating VirtualWorld.");
  58.         theWorld = new VirtualWorld(true);                // true means our code resource floats.
  59.         if(!theWorld || theWorld->Result()) {
  60.             delete theWorld;
  61.             break;
  62.         }
  63.         theData = (WindowDefinitionDataHandle)NewHandle(sizeof(WindowDefinitionData));
  64.         theWindow->dataHandle = (Handle)theData;
  65.         (**theData).world = theWorld;                    // save reference in window record.
  66.         theWorld->Enter();                                // go into our Virtual world.
  67.         // now, allocate the Window object.
  68.         theWindowDef = new WINDOWCLASS;
  69.         if(!theWindowDef) {
  70.             delete theWorld;                            // it didn't work.  get outta here.
  71.             theWorld = nil;
  72.             theWindow->dataHandle = nil;
  73.             break;
  74.         }
  75.         if(commandKeyDown)
  76.             DebugStr("\pCalling WindowDefinition::New().");
  77.         // call it's new method.
  78.         theWindowDef->New(theWindow);
  79.         break;
  80.     case wDispose:
  81.         if(!theWorld) break;
  82.         if(commandKeyDown)
  83.             DebugStr("\pCalling WindowDefinition::Dispose().");
  84.         theWindowDef->Dispose();                        // kill the window def.
  85.         delete theWindowDef;
  86.         theWindowDef = nil;
  87.         delete theWorld;                                // remove our Virtual world.
  88.         theWorld = nil;
  89.         DisposHandle(theWindow->dataHandle);
  90.         theWindow->dataHandle = nil;
  91.         break;
  92.     case wCalcRgns:
  93.         if(!theWorld) break;
  94.         if(commandKeyDown)
  95.             DebugStr("\pCalling WindowDefinition::CalcRgns().");
  96.         theWindowDef->CalcRgns();
  97.         break;
  98.     case wDraw:
  99.         if(!theWorld) break;
  100.         switch((short)param) {
  101.         case wNoHit:
  102.             if(commandKeyDown)
  103.                 DebugStr("\pCalling WindowDefinition::DrawFrame().");
  104.             theWindowDef->DrawFrame();
  105.             break;
  106.         case wInGoAway:
  107.             if(commandKeyDown)
  108.                 DebugStr("\pCalling WindowDefinition::DrawGoAwayBox().");
  109.             theWindowDef->DrawGoAwayBox();
  110.             break;
  111.         }
  112.         break;
  113.     case wDrawGIcon:
  114.         if(!theWorld) break;
  115.         if(commandKeyDown)
  116.             DebugStr("\pCalling WindowDefinition::DrawGIcon().");
  117.         theWindowDef->DrawGIcon();
  118.         break;
  119.     case wGrow:
  120.         if(!theWorld) break;
  121.         if(commandKeyDown)
  122.             DebugStr("\pCalling WindowDefinition::Grow().");
  123.         theWindowDef->DrawGrowImage(*(Rect*)param);
  124.         break;
  125.     case wHit:
  126.         if(!theWorld) break;
  127.         if(commandKeyDown)
  128.             DebugStr("\pCalling WindowDefinition::Hit().");
  129.         result = theWindowDef->Hit(*(Point*)¶m);
  130.         break;
  131.     }
  132.     
  133.     if(theWorld) {
  134.         theWorld->Leave();                                    // go back to previous world.
  135.     }
  136.     
  137.     return result;
  138. }
  139.